package cn.stylefeng.guns.modular.fashion.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;

import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.Fashiotype;
import cn.stylefeng.guns.modular.system.model.Medicaltype;
import cn.stylefeng.guns.modular.fashion.service.IFashiotypeService;

/**
 * 时尚期刊控制器
 *
 * @author fengshuonan
 * @Date 2020-06-20 22:26:57
 */
@Controller
@RequestMapping("/fashiotype")
public class FashiotypeController extends BaseController {

    private String PREFIX = "/fashion/fashiotype/";

    @Autowired
    private IFashiotypeService fashiotypeService;

    /**
     * 跳转到时尚期刊首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "fashiotype.html";
    }

    /**
     * 跳转到添加时尚期刊
     */
    @RequestMapping("/fashiotype_add")
    public String fashiotypeAdd() {
        return PREFIX + "fashiotype_add.html";
    }

    /**
     * 跳转到修改时尚期刊
     */
    @RequestMapping("/fashiotype_update/{fashiotypeId}")
    public String fashiotypeUpdate(@PathVariable Integer fashiotypeId, Model model) {
        Fashiotype fashiotype = fashiotypeService.selectById(fashiotypeId);
        model.addAttribute("item",fashiotype);
        LogObjectHolder.me().set(fashiotype);
        return PREFIX + "fashiotype_edit.html";
    }

    /**
     * 获取时尚期刊列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
    	EntityWrapper<Fashiotype> wrapper = new EntityWrapper<Fashiotype>();
    	wrapper.like("goods_name", condition).or()
    	.like("id", condition);
        return fashiotypeService.selectList(wrapper);
    }

    /**
     * 新增时尚期刊
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Fashiotype fashiotype) {
        fashiotypeService.insert(fashiotype);
        return SUCCESS_TIP;
    }

    /**
     * 删除时尚期刊
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer fashiotypeId) {
        fashiotypeService.deleteById(fashiotypeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改时尚期刊
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Fashiotype fashiotype) {
        fashiotypeService.updateById(fashiotype);
        return SUCCESS_TIP;
    }

    /**
     * 时尚期刊详情
     */
    @RequestMapping(value = "/detail/{fashiotypeId}")
    @ResponseBody
    public Object detail(@PathVariable("fashiotypeId") Integer fashiotypeId) {
        return fashiotypeService.selectById(fashiotypeId);
    }
    
    @InitBinder
   	public void initBinder(WebDataBinder binder) {
   	    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   	    binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));        
   	}
}
